package com.eop.managedBean;

import java.util.List;

import javax.faces.context.FacesContext;

import org.operamasks.faces.annotation.Accessible;
import org.operamasks.faces.annotation.Action;
import org.operamasks.faces.annotation.Bind;
import org.operamasks.faces.annotation.DataModel;
import org.operamasks.faces.annotation.Inject;
import org.operamasks.faces.annotation.ManagedBean;
import org.operamasks.faces.annotation.ManagedBeanScope;
import org.operamasks.faces.annotation.SaveState;
import org.operamasks.faces.component.grid.impl.UIDataGrid;
import org.operamasks.faces.user.util.Browser;

import com.base.commons.SpringBeanHolder;
import com.eop.entity.EmergencyStage;
import com.eop.service.IEmergencyStageService;

@ManagedBean(name = "eop_listEmergencyStageBean", scope = ManagedBeanScope.REQUEST)
public class ListEmergencyStageBean {
	private IEmergencyStageService imsService = SpringBeanHolder
			.getBean("stageService");
	@Inject
	private FacesContext context;
	@Accessible
	@SaveState
	private String eventId = FacesContext.getCurrentInstance()
			.getExternalContext().getRequestParameterMap().get("eventId");
	@Bind(id = "ecyStageGrid", attribute = "binding")
	private UIDataGrid ecyStageGrid_binding;

	@Action(id = "addEmergencyStage")
	public void addEmergencyStage() {
		String url = context.getExternalContext().getRequestContextPath()
				+ "/modules/eop/addEmergencyStage.faces?eventId=" + eventId;
		String script = "showUrl('" + url + "','新增应急阶段')";
		Browser.execClientScript(script);
	}

	@Action(id = "eidtEmergencyStage")
	public void eidtEmergencyStage() {
		Object[] obj = ecyStageGrid_binding.getSelectedValues();
		if (obj == null || obj.length == 0) {
			Browser.execClientScript("window.alert('请选择一条记录 ！');");
			return;
		}
		EmergencyStage es = (EmergencyStage) obj[0];
		String url = context.getExternalContext().getRequestContextPath()
				+ "/modules/eop/addEmergencyStage.faces?id=" + es.getId();
		String script = "showUrl('" + url + "','编辑应急阶段')";
		Browser.execClientScript(script);

	}

	@Action(id = "deleteEmergencyStage")
	public void deleteEmergencyStage() {
		Object[] obj = ecyStageGrid_binding.getSelectedValues();
		if (obj == null || obj.length == 0) {
			Browser.execClientScript("window.alert('请选择一条记录 ！');");
			return;
		}
		EmergencyStage es = (EmergencyStage) obj[0];
		es.setDelFlag(true);
		imsService.saveStage(es);
		ecyStageGrid_binding.reload();
	}
	
	@Action(id = "submit")
	public void showEmergStage() {
		String dirId = context.getExternalContext().getRequestParameterMap()
				.get("dirId");
		String url = context.getExternalContext().getRequestContextPath()
				+ "/modules/eop/showEmergStage.faces?id=" + dirId;
		String script = "showUrl('" + url + "','查看应急阶段')";
		Browser.execClientScript(script);
	}

	@DataModel(id = "ecyStageGrid")
	private List<EmergencyStage> getEcyStageGrid() {
		return imsService.getEmergencyStageByEvent(eventId);
	}
}
